﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;

namespace MenuLib
{
    [Serializable]
    public class MenuHotKeyedItem : MenuItem
    {
        private char hotKey;

        public MenuHotKeyedItem(string name, char hotKey) :
            base(name)
        {
            HotKey = hotKey;
        }

        public MenuHotKeyedItem(string name, string text, char hotKey) :
            base(name, text)
        {
            HotKey = hotKey;
        }

        public char HotKey
        {
            get { return hotKey; }
            protected set { hotKey = value; }
        }

        public override Menu OwnerMenu
        {
            get
            {
                return base.OwnerMenu;
            }
            set
            {
                base.OwnerMenu = value;
                base.OwnerMenu.SetHotKey(HotKey, this);
            }
        }

        #region ISerializable Members

        const string hotKeyValueName = "HotKey";
        const string hotKeyShowModeValueName = "HotKeyShowMode";

        public override void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            base.GetObjectData(info, context);

            info.AddValue(hotKeyValueName, HotKey);
        }

        protected MenuHotKeyedItem(SerializationInfo info, StreamingContext context) :
            base(info, context)
        {
            HotKey = info.GetChar(hotKeyValueName);
        }

        #endregion
    }
}
